package com.bbz.core.lambda.java8.Chapter_8_Refactoring;

public class Validator {
    private  final ValidationStrategy validationStrategy;
    public Validator(ValidationStrategy validationStrategy){
        this.validationStrategy=validationStrategy;
    }
    public boolean validate(String s){
        return validationStrategy.execute(s);
    }
    public static void main(String args[]){
        /**
         * 传统模式使用策略模式
         */
        Validator numericValidator = new Validator(new IsNumeric());
        System.out.println(numericValidator.validate("aaaaaa"));
        Validator lowerCaseValidator = new Validator(new IsAllLowerCase ());
        boolean b2 = lowerCaseValidator.validate("bbbb");
        /**
         * lambda方式实现策略模式
         */
        Validator numValidator=new Validator((String s)->s.matches("\\d+"));
        System.out.println(numValidator.validate("aaaaaa"));

    }
}
